var t = getApp();

Component({
    properties: {
        defaultData: {
            type: Object,
            value: []
        },
        templates: {
            type: Array,
            value: []
        }
    },
    data: {
        isShowPopup: !1,
        showTemplate: !1,
        dispatchData: {},
        radio: 0,
        dispatchPrice: "",
        columns: [],
        checkTemplate: {},
        templateName: "",
        defautlIndex: 0
    },
    lifetimes: {
        attached: function() {
            var t = this.properties.defaultData, a = 0, e = "默认模版";
            t.dispatch_id && this.data.templates && this.data.templates.forEach(function(i, s) {
                t.dispatch_id == i.id && (a = s, e = i.dispatch_name);
            }), this.setData({
                dispatchData: t,
                defautlIndex: a,
                templateName: e
            });
        }
    },
    methods: {
        showPopup: function() {
            this.setData({
                isShowPopup: !this.data.isShowPopup
            });
        },
        changeType: function(t) {
            this.setData({
                "dispatchData.dispatch_type": t.detail
            });
        },
        checkDisTemplate: function() {
            this.setData({
                isShowPopup: !1,
                showTemplate: !0
            });
        },
        confirmTemplate: function(t) {
            var a = t.detail.value;
            this.setData({
                templateName: a.dispatch_name,
                checkTemplate: a,
                "dispatchData.dispatch_id": a.id
            }), this.cancelTemplate();
        },
        cancelTemplate: function() {
            this.setData({
                isShowPopup: !0,
                showTemplate: !1
            });
        },
        onClick: function(t) {
            var a = t.currentTarget.dataset.name;
            this.setData({
                "dispatchData.dispatch_type": a
            });
        },
        changeText: function(t) {
            var a = t.detail.value;
            this.data.dispatchData.dispatch_price = a;
        },
        confirmType: function(a) {
            if (1 == this.data.dispatchData.dispatch_type && "" == this.data.dispatchData.dispatch_price) return t.tips("请填写统一邮费");
            this.showPopup(), this.triggerEvent("confirmType", this.data.dispatchData);
        }
    }
});